﻿@{
    ViewBag.Title = "角色配置";
    Layout = "~/Views/Shared/Dwz/_DwzPageLayout.cshtml";
}
<div layouth="100" style="float: left; display: block; overflow: auto; width: 200px;
    border: solid 1px #99BBE8; line-height: 21px; background: #fff; margin-left: 10px;">
    <div class="panelBar">
        <ul class="toolBar">
            <li class=""><a class="add"  target="dialog" href="@Url.Action("AddRole")"><span>添加角色</span>
            </a></li>
            <li><a class="delete" id="SetAccountDelRole"><span>删除</span></a></li>
        </ul>
    </div>
    <div id="SetUserRolesTreeDiv">
    </div>
</div>
<div layouth="100" style="float: left; display: block; overflow: auto; width: 200px;
    border: solid 1px #99BBE8; line-height: 21px; background: #fff; margin-left: 10px;">
    <div class="panelBar">
        <ul class="toolBar">
            @*<li class=""><a class="add" target="dialog" href=""><span>添加用户</span> </a></li>*@
            <li class=""><a class="add" id="UsersSetUserJoinRole"><span>加入角色</span> </a></li>
        </ul>
    </div>
    <ul id="SetUserUsersTree">
        @foreach (MembershipUser u in Membership.GetAllUsers())
        { 
            <li title="@u.UserName" ><span>@u.UserName </span></li>
        }
    </ul>
</div>
<script type="text/javascript">
    $("#SetUserUsersTree").ligerTree({ checkbox: true, nodeWidth: 130 }); //构建用户树

    //刷新角色树
    function RolesTreeLoad(json){
        $("#SetUserRolesTreeDiv").ajaxUrl({
				type:"POST", url:"@Url.Action("RolesTree")", callback:function(response){               
                    $("#SetUserRolesTreeDiv #RolesTree").ligerTree({ checkbox: false, nodeWidth: 155 }); //构建角色树
				}						
			});       
            if(json)DWZ.ajaxDone(json);    
     }
    RolesTreeLoad();
    $("#UsersSetUserJoinRole").click(function () {
        var Roletext = $("#SetUserRolesTreeDiv #RolesTree").ligerGetTreeManager().getSelected().data.text;        
        alert(Roletext);
        var usernames = "";
        $.each($("#SetUserUsersTree").ligerGetTreeManager().getChecked(),
            function(i,val){
            usernames+=(i==0?val.data.text:","+val.data.text);
        });
        alert(usernames);
        $.post("@Url.Action("UserJoinRole")",
        {Role:Roletext,users:usernames},
        function(response){
            DWZ.ajaxDone(response);
        });
       RolesTreeLoad();
    });
</script>
